package com.jdbc_;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Jdbc3 {
    // 连接方式三，使用DriverManager 替代 Driver 进行统一管理
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
        // 1、反射加载Driver
        Class<?> clz = Class.forName("com.mysql.jdbc.Driver");
        Driver driver = (Driver) clz.newInstance();
        // 注册Driver驱动
        DriverManager.registerDriver(driver);

        // 2、获取连接
        // 创建url、user和password
        String url = "jdbc:mysql://localhost:3306/hsp2";
        String user = "root";
        String password = "lxl";

        Connection connection = DriverManager.getConnection(url, user, password);
        System.out.println("第三种方式获取到的连接：" + connection);
    }
}
